//
//  AY_ShuDouItemCell.m
//  AiYue
//
//  Created by boWen on 2023/11/21.
//

#import "AY_ShuDouItemCell.h"

@interface AY_ShuDouItemCell ()
@property (nonatomic,strong) UIView * bg_View;//底部圆角
@property (strong,nonatomic) UIImageView *tipsImageView;
@property (strong,nonatomic) UILabel *tipsLabel;
@property (strong,nonatomic) UILabel *topTitleLabel;
@property (strong,nonatomic) UILabel *midTitleLabel;
@property (strong,nonatomic) UILabel *bottomTitleLabel;
@end

@implementation AY_ShuDouItemCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.bg_View = [AYTool createViewWithFrame:CGRectZero andBg:COLOR(@"#FFFFFF") andRadius:YNUM(8) andAddSubView:self.contentView];
        self.bg_View.layer.borderWidth = 2.0f;
        self.bg_View.layer.borderColor = COLOR(@"#EAEAEA").CGColor;
        self.bg_View.backgroundColor = COLOR(@"#FFFFFF");
        
        [self.bg_View mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.equalTo(self.contentView);
        }];
        
        self.tipsImageView = [AYTool createImageViewWithFrame:CGRectZero andImage:nil andBg:THEME_COLOR andRadius:1 andAddSubView:self.contentView];
        [self.tipsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView);
            make.top.equalTo(self.contentView).offset(YNUM(-10));
            make.height.mas_offset(YNUM(22));
            make.width.mas_offset(YNUM(52));
        }];
        
        self.tipsLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:[UIColor whiteColor] andBgColor:nil andFont:YFont(12) andLines:1 andRadius:0 andAddSubView:self.tipsImageView];
        self.tipsLabel.textAlignment = NSTextAlignmentCenter;
        [self.tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.right.left.bottom.equalTo(self.tipsImageView);
        }];
        
        
        self.midTitleLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#010101") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:24] andLines:2 andRadius:0 andAddSubView:self.contentView];
    
        [self.midTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.bg_View).offset(YNUM(-10));
            make.centerX.equalTo(self.bg_View);
            make.height.mas_offset(YNUM(35));
        }];
        
        self.bottomTitleLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#BFBFBF") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:16] andLines:2 andRadius:0 andAddSubView:self.contentView];
        self.bottomTitleLabel.textAlignment = NSTextAlignmentCenter;
        [self.bottomTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.bg_View).offset(YNUM(-33));
            make.left.equalTo(self.bg_View).offset(YNUM(5));
            make.right.equalTo(self.bg_View).offset(YNUM(-5));
            make.height.mas_offset(YNUM(20));
        }];
        
    }
    return self;
}


- (void)setSelected:(BOOL)selected {
    [super setSelected:selected];
    if(selected) {
        self.bg_View.layer.borderWidth = 2.0f;
        self.bg_View.layer.borderColor = THEME_COLOR.CGColor;
        self.bg_View.backgroundColor = COLOR(@"#FFF0EC");
        self.midTitleLabel.textColor = THEME_COLOR;
        self.bottomTitleLabel.textColor = THEME_COLOR;
    }else {
        self.bg_View.layer.borderWidth = 2.0f;
        self.bg_View.layer.borderColor = COLOR(@"#EAEAEA").CGColor;
        self.bg_View.backgroundColor = COLOR(@"#FFFFFF");
        self.midTitleLabel.textColor = COLOR(@"#010101");
        self.bottomTitleLabel.textColor = COLOR(@"#BFBFBF");
    }
}



- (void)setVpSubModel:(VpProductModel *)vpSubModel {
    _vpSubModel = vpSubModel;
    if ([vpSubModel.tipStr isEqual:@"0"] || [vpSubModel.tipStr isEqual:@"10"]) {
        self.tipsImageView.hidden = YES;
    }else {
        self.tipsImageView.hidden = NO;
        self.tipsLabel.text = [NSString stringWithFormat:@"限时%@折",vpSubModel.tipStr];
        [self.tipsImageView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(YNUM(self.tipsLabel.text.length*15));
        }];
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, YNUM(self.tipsLabel.text.length*15), YNUM(22)) byRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii:CGSizeMake(YNUM(11), YNUM(11))];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = self.tipsImageView.bounds;
        maskLayer.path = maskPath.CGPath;
        self.tipsImageView.layer.mask = maskLayer;
    }
    
    self.midTitleLabel.text = [NSString stringWithFormat:@"%@书豆", kStringUtils(_vpSubModel.assetAmount)];
    NSString *labelText = self.midTitleLabel.text;
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
    NSRange rangeA = [labelText rangeOfString:@"书豆"];
    [attributedString addAttribute:NSFontAttributeName value:YFont(12) range:rangeA];
    self.midTitleLabel.attributedText = attributedString;
    
    self.bottomTitleLabel.text = [NSString stringWithFormat:@"￥%@", kStringUtils(_vpSubModel.price)];
}

- (NSString *)getDiscount:(NSInteger)discountValue {
    switch (discountValue) {
        case 0:
            return @"";
            break;
        case 10:
            return @"";
            break;
            
        default:
            return @"";
            break;
    }
}
@end
